
<h1><span></span><?= lang('label_shoping_cart') ?></h1>

<ul class="breadcrumb">
    <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
    <li><a href="<?= base_url('user/profile') ?>"><?= lang('label_profile') ?></a></li>
    <li><?= lang('label_shoping_cart') ?></li>
</ul>


<div class="page">
    <?php
    if ($data && isset($items) && $items) {
        $total = 0;
        $shiping = 0;
        $discount = 0;
        if ($this->user_id)
            $cities = get_shiping_cities_id();
        ?>
        <form class="forms inside_1" action="<?php echo base_url('cart/update') ?>" method="post">
            <table id="tablestyle" class="shopping_cart">
                <thead>
                    <tr>
                        <th style="width:400px;"><?= lang('label_products') ?></th>
                        <th style="width:80px;"><?= lang('label_product_quentity') ?></th>
                        <th style="width:150px;"><?= lang('label_shiping') . ' ' . lang('label_details') ?></th>
                        <th style="width:110px;"><?= lang('label_product_price') ?></th>
                    </tr>
                </thead>

                <tbody>
                    <?php
                    foreach ($items as $item) {
                        $product = get_product_from_id($item->product_id);
                        if ($product) {
                            $images = unserialize($product->images);
                            $nodef = TRUE;
                            ?>
                            <tr>
                                <td>
                                    <div class="item_cart">
                                        <samp>
                                            <img src="<?php
                                            if (count($images) > 0) {
                                                foreach ($images as $k => $v) {
                                                    if ($v[1] == 'yes') {
                                                        $nodef = false;
                                                        $defimage = $v[0];
                                                        echo base_url(PRODUCT_PATH . $v[0]);
                                                    }
                                                } if ($nodef) {
                                                    base_url(PRODUCT_PATH . $images[0][0]);
                                                    $defimage = $images[0][0];
                                                }
                                            } else {
                                                echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) . '/' . APPPATH . 'views/' . $this->themes->Cms_themes() . '/images/noimage_' . LANG . '.gif';
                                            }
                                            ?>" alt="" />
                                            <a class="item_del" href="<?= base_url("cart/remove/$item->product_id") ?>"></a>
                                            <a class="item_viw" target="_blank" href="<?= base_url("products/view/$item->product_id") ?>"></a>
                                        </samp>

                                        <span><?= $product->name ?></span>
                                        <p><?= lang('label_by') ?> : <a target="_blank" href="<?= base_url("store/index/$product->store_id") ?>"><?= $product->value ?></a></p>
                                        <p><?= lang('label_product_price') ?> : <b><?= $price = ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?></b> <?= lang('label_rial') ?></p>
                                        <p><?= lang('label_prod_condition') ?> : <b><?= lang('label_condition_' . strtolower($product->condition)) ?></b></p>
                                        <div class="select">
                                            <label><?= lang('label_menu_link_addressbooks') ?> :</label>

                                            <?php if ($this->user_id) { ?>
                                                <samp>
                                                    <select name="address[<?= $item->id ?>]">
                                                        <option value="0"><?= lang('label_select_address') ?></option>
                                                        <?php if (count($address) > 0) { ?>
                                                            <?php foreach ($address as $adr) { ?>
                                                                <option value="<?= $adr->id ?>" <?= ($adr->id == $item->address) ? 'selected' : '' ?>><?= $adr->name ?></option>

                                                            <?php } ?>
                                                        <?php } ?>
                                                    </select>
                                                    <span><a href="<?= base_url('addressbook/add') ?>" target="_blank"><?= lang('label_add_address') ?></a></span>
                                                </samp>
                                            
                                            <?php } else { ?>
                                                <span style="color: red">
                                                    <?= lang('message_login_first') ?>
                                                </span>
                                            <?php } ?>

                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <div class="text" style="padding:0 0 6px 0;">
                                        <samp>
                                            <input type="number" name="amount[<?= $item->id ?>]" value="<?= $item->amount ?>" placeholder="<?= lang('label_product_quentity') ?>" style="width: 76px;min-width: 60px;padding: 10px 2px;margin: 0;" />
                                        </samp>
                                    </div>
                                    <?php
                                    $colors = unserialize($product->colors);
                                    if (count($colors) > 1) {
                                        ?>
                                        <div class="select" >
                                            <samp style="width: 60px; min-width: 0 !important; margin: 0 0 6px;">
                                                <select name="color[<?= $item->id ?>]" class="cartcolor" style="width:60px;">
                                                    <?php foreach ($colors as $k => $v) { ?>
                                                        <option value="<?= $v ?>" style="background-color: <?= $v ?>" <?php if ($item->color == $v) echo 'selected' ?>></option>
                                                    <?php } ?>
                                                </select>
                                            </samp>
                                        </div>
                                    <?php } ?>

                                    <?php
                                    $size = unserialize($product->size);
                                    if (count($size) > 1) {
                                        ?>
                                        <div class="select" >
                                            <samp style="width: 60px; min-width: 0 !important">
                                                <select name="size[<?= $item->id ?>]" style="width: 60px">
                                                    <?php foreach ($size as $k => $v) { ?>
                                                        <option value="<?= $v ?>" <?php if ($item->size == $v) echo 'selected' ?>><?= $v ?></option>
                                                    <?php } ?>
                                                </select>
                                            </samp>
                                        </div>
                                    <?php } ?>

                                    </div>
                                </td>
                                <td>
                                    <?php if ($this->user_id) { ?>
                                        <?php if ($item->city_id) { ?>
                                            <b><?=
                                                $item->shiping;
                                                $shiping += $item->shiping;
                                                ?></b> <small><?= lang('label_rial') ?></small>
                                            <div class="radio">
                                                <samp>
                                                    <?php if (in_array($item->city_id, $cities)) { ?>
                                                        <input type="radio" name="shipingtype[<?= $item->id ?>]" value="cashdelivery" id="cashdelivery<?= $item->id ?>" <?php if ($item->cash_on_delivery == 'YES') echo 'checked' ?> ><label for="cashdelivery<?= $item->id ?>"><?= lang('label_cash_on_delivery') ?></label><br>
                    <?php } ?>
                                                    <input type="radio" name="shipingtype[<?= $item->id ?>]" value="gethand" id="gethand<?= $item->id ?>" <?php if ($item->get_by_hand == 'YES') echo 'checked' ?> /><label for="gethand<?= $item->id ?>"><?= lang('label_get_by_hand') ?></label>
                                                </samp>
                                            </div>
                                            <?php } else { ?>
                                            <h4 style="color: red">
                                            <?= lang('message_select_your_address') ?>
                                            </h4>
                                        <?php } ?>
                                        <?php } else { ?>
                                        <h4 style="color: red">
                                        <?= lang('message_login_first') ?>
                                        </h4>
            <?php } ?>
                                </td>
                                <td>
                                    <strong><?=
                                        $item->total_price;
                                        $total += $price * $item->amount
                                        ?></strong> <small><?= lang('label_rial') ?></small>
                                </td>
                            </tr>
                            <?php
                        }
                        $discount += $item->discount;
                    }
                    ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="3"><?= lang('label_sub_total') ?></td>
                        <td><?= $total ?></td>
                    </tr>
                    <tr>
                        <td colspan="3"><?= lang('label_shiping_total') ?></td>
                        <td><?= $shiping ?></td>
                    </tr>
                    <tr>
                        <td colspan="3"><?= lang('label_discount_total') ?></td>
                        <td><?= $discount ?></td>
                    </tr>
                    <tr>
                        <th colspan="3"><?= lang('label_item_total') ?></th>
                        <th><strong><?= $total + $shiping - $discount ?></strong> <small><?= lang('label_rial') ?></small></th>
                    </tr>
                </tfoot>
            </table>

            <div class="submit">
                <input name="submit" value="<?= lang('label_update') ?>" type="submit"  >
                <input name="checkout" value="<?= lang('label_checkout') ?>" type="button" onclick="
                            if (confirm('<?= lang('message_lose_not_saved') ?>')) {
                                location.href = '<?= base_url('cart/checkout') ?>'
                            } else {
                                return false;
                            }"  >
            </div>


        </form>
<?php } else { ?>
        <div class="unsaved">
            <img src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/images/unsaved.png" alt="" />
            <br /><?= lang('message_no_products') ?>
        </div>
        <br /><br /><br /><br />
<?php } ?>
</div>
